
export class MemCanvas{
    private canvas:HTMLCanvasElement;
    ctx:CanvasRenderingContext2D;

    constructor(width:number, height:number){
        let canvas = this.canvas = document.createElement('canvas');
        canvas.width = width;
        canvas.height = height;
        this.ctx = canvas.getContext('2d');
    }

    clear(){
        this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);
    }

    fillRect(x:number, y:number, width:number, height:number, color:string){
        let ctx = this.ctx;
        ctx.fillStyle = color;
        ctx.fillRect(x,y,width,height);
    }

    circle(x:number,y:number, r:number, color:string){
        let ctx = this.ctx;
        ctx.fillStyle = color;
        ctx.beginPath();
        ctx.arc(x,y,r, 0, 2 * Math.PI);
        ctx.fill();
    }

    toBuffer(){
        let pngUrl = this.canvas.toDataURL("image/png");
        // const img = new Image();
        // img.src = pngUrl;
        // document.body.appendChild(img);        
    }
}